package dto

import (
	"go-admin/app/admin/models"

	"go-admin/common/dto"
	common "go-admin/common/models"
)

type SysTemplateGetPageReq struct {
	dto.Pagination `search:"-"`
	TypeId         int    `form:"typeId" search:"type:exact;column:type_id;table:sys_template" comment:"模版类型"`
	Title          string `form:"title" search:"type:exact;column:title;table:sys_template" comment:"模版名称"`
	IsTpl          bool   `form:"isTpl" search:"type:exact;column:is_tpl;table:sys_template" comment:"模版是否文件"`
	Content        string `form:"content" search:"type:exact;column:content;table:sys_template" comment:"模版是否文件"`
	Status         string `form:"status" search:"type:exact;column:status;table:sys_template" comment:"状态"`
	MemberType     `search:"type:left;on:type_id:id;table:sys_template;join:sys_template_type"`
	SysMemberOrder
}

type SysTemplateOrder struct {
	IdOrder        string `search:"type:order;column:id;table:sys_template" form:"idOrder"`
	StatusOrder    string `search:"type:order;column:status;table:sys_template" form:"statusOrder"`
	CreatedAtOrder string `search:"type:order;column:created_at;table:sys_template" form:"createdAtOrder"`
}

type TemplateType struct {
	TypeId string `search:"type:contains;column:id;table:sys_template_type" form:"typeId"`
}

func (m *SysTemplateGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type UpdateSysTemplateStatusReq struct {
	Id     int    `json:"id" comment:"模版ID" vd:"$>0"` // 模版ID
	Status string `json:"status" comment:"状态" vd:"len($)>0"`
	common.ControlBy
}

func (s *UpdateSysTemplateStatusReq) GetId() interface{} {
	return s.Id
}

func (s *UpdateSysTemplateStatusReq) Generate(model *models.SysTemplate) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.Status = s.Status
}

type SysTemplateInsertReq struct {
	Id      int    `json:"id" comment:"模版ID"` // 模版ID
	TypeId  int    `json:"typeId" comment:"模版类型" default:"0"`
	Title   string `json:"title" comment:模版名称" vd:"len($)>0"`
	IsTpl   bool   `json:"isTpl" comment:模版是否文件"`
	Content string `json:"content" gorm:"comment:模版是否文件"`
	Remark  string `json:"remark" comment:"备注"`
	Status  string `json:"status" comment:"状态" default:"1"`
	common.ControlBy
}

func (s *SysTemplateInsertReq) Generate(model *models.SysTemplate) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.TypeId = s.TypeId
	model.Title = s.Title
	model.IsTpl = s.IsTpl
	model.Content = s.Content
	model.Remark = s.Remark
	model.Status = s.Status
}

func (s *SysTemplateInsertReq) GetId() interface{} {
	return s.Id
}

type SysTemplateUpdateReq struct {
	Id      int    `json:"id" comment:"模版ID"`                 // 模版ID
	TypeId  int    `json:"typeId" comment:"模版类型" default:"0"` // 模版类型
	Title   string `json:"title" comment:模版名称" vd:"len($)>0"`
	IsTpl   bool   `json:"isTpl" comment:模版是否文件"`
	Content string `json:"content" gorm:"comment:模版是否文件"`
	Remark  string `json:"remark" comment:"备注"`
	Status  string `json:"status" comment:"状态" default:"1"`
	common.ControlBy
}

func (s *SysTemplateUpdateReq) Generate(model *models.SysTemplate) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.TypeId = s.TypeId
	model.Title = s.Title
	model.IsTpl = s.IsTpl
	model.Content = s.Content
	model.Remark = s.Remark
	model.Status = s.Status
}

func (s *SysTemplateUpdateReq) GetId() interface{} {
	return s.Id
}

type SysTemplateById struct {
	dto.ObjectById
	common.ControlBy
}

func (s *SysTemplateById) GetId() interface{} {
	if len(s.Ids) > 0 {
		s.Ids = append(s.Ids, s.Id)
		return s.Ids
	}
	return s.Id
}

func (s *SysTemplateById) GenerateM() (common.ActiveRecord, error) {
	return &models.SysTemplate{}, nil
}
